package com.lee9213.thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author libo
 * @version 1.0
 * @date 2017/7/27 15:31
 */
public class CyclicBarrierTest {

    static CyclicBarrier barrier = new CyclicBarrier(2,new A());

    static class A implements Runnable {
        @Override
        public void run() {
            System.out.println(3);
        }
    }


    public static void main(String[] args) {
        new Thread(() -> {
            try {
                barrier.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (BrokenBarrierException e) {
                e.printStackTrace();
            }
            System.out.println(1);
        }).start();

        try {
            barrier.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }

        System.out.println(2);
    }
}
